package com.ruoyi.hospital.controller.prescriptionInfo;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.prescriptionInfo.PrescriptionDrug;
import com.ruoyi.hospital.service.prescriptionInfo.IPrescriptionDrugService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 处方药品信息表Controller
 * 
 * @author wendao
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/hospital/prescriptionDrug")
public class PrescriptionDrugController extends BaseController
{
    @Autowired
    private IPrescriptionDrugService prescriptionDrugService;

    /**
     * 查询处方药品信息表列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:prescriptionDrug:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrescriptionDrug prescriptionDrug)
    {
        startPage();
        List<PrescriptionDrug> list = prescriptionDrugService.selectPrescriptionDrugList(prescriptionDrug);
        return getDataTable(list);
    }

    /**
     * 导出处方药品信息表列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:prescriptionDrug:export')")
    @Log(title = "处方药品信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrescriptionDrug prescriptionDrug)
    {
        List<PrescriptionDrug> list = prescriptionDrugService.selectPrescriptionDrugList(prescriptionDrug);
        ExcelUtil<PrescriptionDrug> util = new ExcelUtil<PrescriptionDrug>(PrescriptionDrug.class);
        util.exportExcel(response, list, "处方药品信息表数据");
    }

    /**
     * 获取处方药品信息表详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:prescriptionDrug:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(prescriptionDrugService.selectPrescriptionDrugById(id));
    }

    /**
     * 新增处方药品信息表
     */
    @PreAuthorize("@ss.hasPermi('hospital:prescriptionDrug:add')")
    @Log(title = "处方药品信息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrescriptionDrug prescriptionDrug)
    {
        return toAjax(prescriptionDrugService.insertPrescriptionDrug(prescriptionDrug));
    }

    /**
     * 修改处方药品信息表
     */
    @PreAuthorize("@ss.hasPermi('hospital:prescriptionDrug:edit')")
    @Log(title = "处方药品信息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrescriptionDrug prescriptionDrug)
    {
        return toAjax(prescriptionDrugService.updatePrescriptionDrug(prescriptionDrug));
    }

    /**
     * 删除处方药品信息表
     */
    @PreAuthorize("@ss.hasPermi('hospital:prescriptionDrug:remove')")
    @Log(title = "处方药品信息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(prescriptionDrugService.deletePrescriptionDrugByIds(ids));
    }
}
